package com.example.demo.web.manage.controller;

import com.example.demo.web.common.annotation.OperateLog;
import com.example.demo.web.manage.dto.DeptDto;
import com.example.demo.web.manage.service.DeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.noear.solon.annotation.*;
import org.noear.solon.core.handle.ModelAndView;

@Controller
@Mapping("/dept")
@Api("部门管理")
@Slf4j
public class DeptController {
  @Inject private DeptService service;

  @Mapping(value = "list")
  @Get
  @ApiOperation("获取列表")
  @OperateLog
  public List<DeptDto> list() {
    log.info("dept list");
    return service.list();
  }

  @Mapping
  @Post
  @ApiOperation("新增")
  public Boolean add(@Body DeptDto deptDto) {
    return service.add(deptDto);
  }

  @Mapping
  @Put
  @ApiOperation("更新")
  public Boolean update(@Body DeptDto deptDto) {
    return service.update(deptDto);
  }

  @Mapping("/{id}")
  @Get
  @ApiOperation("获取")
  public DeptDto get(@Path Long id) {
    return service.get(id);
  }

  @Mapping
  @Delete
  @ApiOperation("删除")
  public Boolean delete(@Param Long id) {
    return service.delete(id);
  }

  @Mapping("/index")
  @Get
  @ApiOperation("浏览部门")
  public ModelAndView index() {
    ModelAndView mv = new ModelAndView();
    mv.put("depts", service.list());
    mv.view("dept.shtm");

    return mv;
  }
}
